//
//  DPQualityAssurance.m
//  UITestingKit
//
//  Created by Ofri Wolfus on 19/03/07.
//  Copyright 2007 Ofri Wolfus. All rights reserved.
//

#import "DPQualityAssurance-Private.h"
#import "DPAccessibilityNotificationCenter.h"


@implementation DPQualityAssurance

+ (NSString *)testedElement {
	return nil;
}

- (void)_UIElementDestroyed:(NSNotification *)notif {
	[[self class] _takeTesterDown:self];
}

- (id)initWithElement:(DPUIElement *)e {
	if ((self = [super init])) {
		_element = [e retain];	// messages to nil always return nil
		if (_element)
			[[DPAccessibilityNotificationCenter defaultCenter] addObserver:self
																  selector:@selector(_UIElementDestroyed:)
																	  name:(NSString *)kAXUIElementDestroyedNotification
																	object:_element];
	}
	
	return self;
}

- (id)init {
	return [self initWithElement:nil];
}

- (void)dealloc {
	[[DPAccessibilityNotificationCenter defaultCenter] removeObserver:self];
	[_element release]; _element = nil;
	[super dealloc];
}

- (DPUIElement *)UIElement {
	return _element;
}

@end
